#!/usr/bin/env python
# -*- coding: UTF-8 -*-
"""
@Project : gtmsAutoTestProject 
@File    : member_deleted_server.py
@IDE     : PyCharm 
@Author  : Mario
@Date    : 2022/5/11 17:37 
@Describe: 会员数据删除业务实现
"""
from Comm.sqlUtils.mysqlControl import MysqlHandler


def member_deleted(phone, brandCode):
    """
    删除数据库会员数据
    :param phone: 手机号
    :param brandCode: 品牌编码
    :return:
    """
    mysql_conn = MysqlHandler('member')
    # 查询customer表的SQL语句
    customer_id_sql = "SELECT id FROM `customer` WHERE `phone` = '{}' and deleted = '0' and brand_code = '{}'".format(
        phone, brandCode)
    customer_id = str(mysql_conn.table_select(customer_id_sql))  # 调用查询方法
    # 判断查询到的数据是否为空,为空代表当前手机号&品牌没有可删除的会员数据
    if customer_id != "None":  # 如果查询到会员数据就进行相关的删除操作
        # 修改customer相关三表会员数据SQL
        updated_customer_table_sql = "UPDATE `customer` SET `deleted`='1' WHERE (`id`='{}')".format(customer_id)
        updated_customerCard_table_sql = "UPDATE `customer_card` SET `deleted`='1' WHERE (`customer_id`='{}')".format(
            customer_id)
        updated_customerOpenRelation_table_sql = "UPDATE `customer_open_relation` SET `deleted`='1' WHERE (`customer_id`='{}')".format(
            customer_id)
        # 修改customer相关三表会员数据操作
        mysql_conn.table_updated(updated_customer_table_sql)
        mysql_conn.table_updated(updated_customerCard_table_sql)
        mysql_conn.table_updated(updated_customerOpenRelation_table_sql)
        mysql_conn.close()  # 关闭数据库连接
        info_message = "会员[{}]数据已删除~".format(customer_id)
        return info_message

    else:  # 查询不到会员数据就返回响应提示信息
        mysql_conn.close()  # 关闭数据库连接
        warning_message = "当前手机号[{}]&品牌编码[{}]查询到的会员数据为空。请检查请求参数后重试~".format(phone, brandCode)
        return warning_message


if __name__ == '__main__':
    member_deleted('18682241673', '823882')
